package com.ckjw.gobang.utils;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
 * 查看本机参数类
 * @author lck and djw
 * @Date 2022年6月4日-下午2:26:39
 */
public class MyIPTool {
	
	public static List<String> getAllLocalHostIP()
	{
		List<String> allip=new ArrayList<>();
	    try {
            Enumeration<?> netInterfaces = NetworkInterface.getNetworkInterfaces();
            while (netInterfaces.hasMoreElements()) {
                NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
                Enumeration<?> nii = ni.getInetAddresses();
                while (nii.hasMoreElements()) {
                    InetAddress ip = (InetAddress) nii.nextElement();
                    if (!ip.getHostAddress().contains(":")) {
                        allip.add(ip.getHostAddress());
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
		
		return allip;
	}

}
